import 'package:flutter/material.dart';
import 'package:flutter_project/moudle/demo_page/theme_language_change.dart';
import 'package:flutter_project/moudle/root/cus_bottom_tab_item.dart';
import 'package:flutter_project/moudle/root/tabar_logic.dart';
import 'package:get/get.dart';

class TabarPage extends GetView<TabarLogic> {
  const TabarPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: PopScope(
        canPop: false,
        child: _buildContent(),
      ),
      bottomNavigationBar: _buildTabBar(),
    );
  }

  Widget _buildContent() {
    return PageView.builder(
      itemBuilder: (context, index) {
        switch (index) {
          case 0:
            return ThemeLanguageChange();
          case 1:
            return Container(color: Colors.green);
          case 2:
            return Container(color: Color.fromARGB(255, 61, 66, 157));
          case 3:
            return Container(color: Color.fromARGB(255, 210, 153, 153));
          default:
            return Container();
        }
      },
      itemCount: controller.tabs.length,
      physics: const NeverScrollableScrollPhysics(),
      controller: controller.pageController,
      onPageChanged: (index) {},
    );
  }

  Widget _buildTabBar() {
    final con = Get.put(TabarLogic());
    return Obx(
      () {
        return Visibility(
          visible: con.isShowTabar.value,
          child: Container(
            color: Colors.white,
            child: SafeArea(
              child: Container(
                height: 60,
                color: Colors.white,
                child: Row(
                  children: List.generate(
                    con.tabs.length,
                    (index) {
                      return CusBottomTabItem(
                          isSelected: con.currentIndex.value == index,
                          tabModel: con.tabs[index],
                          onTap: () {
                            con.switchTo(index);
                          });
                    },
                  ),
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}
